﻿Public Class frmAnmeldung

    Private WithEvents BC As clsSymbolScanner
    Private bLogin As Boolean = False

#Region "Events"

    Private Sub Barcode_Scanned(ByVal bstrBarCode As String, ByVal bstrSource As String, ByVal lStatus As Integer, ByVal lLabelType As Integer, ByVal lDataLength As Integer) Handles BC.ScanComplete

        Try

            If bstrBarCode.Trim = "" Then Throw New Exception("Bitte scannen Sie einen gültigen Wert !")

            Cursor.Current = Cursors.WaitCursor
            Dim PTS As New PaketTrackerService.Webservices

            clsData.Mitarbeiter = PTS.IsMitarbeiterValid(bstrBarCode)
            If clsData.Mitarbeiter Is Nothing Then Throw New Exception("Ungültiger Benutzer !")

            bLogin = True

            'Den Miterbeiter erfassen
            clsGlobals.ShowForm(Me, frmHauptmenue)

        Catch ex As Exception
            Cursor.Current = Cursors.Default
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        Finally
            Cursor.Current = Cursors.Default
        End Try

    End Sub

    Private Sub frmAnmeldung_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

        If IsNothing(BC) Then BC = New clsSymbolScanner
        BC.Enabled = True

        bLogin = False

    End Sub

    Private Sub frmAnmeldung_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

        If MsgBox("Möchten Sie die Anwendung beenden ?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.No Then
            e.Cancel = True
            Exit Sub
        End If

        Application.Exit()

    End Sub

    Private Sub frmAnmeldung_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate

        If Not IsNothing(BC) Then BC.Enabled = False
        If Not IsNothing(BC) Then BC.Dispose()
        BC = Nothing

        If Not bLogin Then Me.Close()

    End Sub

#End Region

End Class
